package learningApp.Accessories;

import java.util.Set;

public class Chi
{
	private ChiValue _value;
	
	public Chi(ChiValue value)
	{
		_value = value;
	}
	
	public int GetChiValueAsInt() throws Exception
	{
		switch(_value)
		{
		case PLUS:
			return 1;
		case MINUS:
			return -1;
		case INVALID:
			throw new Exception("INVALID chi value");
		default:
			throw new Exception("Unknown chi value");
		}
	}
	
	public void Multiply(ChiValue otherChi)
	{
		if(_value == ChiValue.INVALID || otherChi == ChiValue.INVALID)
		{
			_value =  ChiValue.INVALID;
		}
		_value = (_value == otherChi ? ChiValue.PLUS : ChiValue.MINUS);
	}
	
	public static Chi CalcChi(Set<Integer> T, VariableAssignment assignment)
	{
		Chi product = new Chi(ChiValue.PLUS);
		
		for(int i : T)
		{
			product.Multiply(assignment.GetValueAtIndex(i));
		}
		return product;
	}

}